﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LibNiconico.NiconicoApi.Extentions
{
    internal class MultiPartFormData:List<KeyValuePair<string,string>>
    {
        private const string FORMDATA_TEMPLATE = "--{0}\r\nContent-Disposition: form-data; name=\"{1}\"\r\n\r\n{2}\r\n";

        internal string Boundary { get; private set; }

        internal MultiPartFormData()
        {
            this.Boundary = "BOUNDARY";
        }

        public void Add(string key, string val)
        {
            
            this.Add(new KeyValuePair<string, string>(key, val));
            
        }

        public override string ToString()
        {
            var stringData = "";
            foreach (var keyValue in this)
            {
                stringData += string.Format(FORMDATA_TEMPLATE,this.Boundary, keyValue.Key, keyValue.Value);
            }
            stringData += "--" + this.Boundary + "--\r\n";
            return stringData;
        }
    }
}
